package com.gxa.service.impl;

import com.gxa.mapper.AdministratorsMapper;
import com.gxa.mapper.PremiereMeunMapper;
import com.gxa.pojo.Administrators;
import com.gxa.pojo.PremiereMeun;
import com.gxa.service.AdministratorsService;
import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Administrators)表服务实现类
 *
 * @author makejava
 * @since 2020-11-26 19:45:14
 */
@Service
public class AdministratorsServiceImpl implements AdministratorsService {
    @Autowired(required = false)
    private AdministratorsMapper administratorsMapper;
    @Autowired(required = false)
    private PremiereMeunMapper premiereMeunMapper;

    @Override
    public List<Administrators> queryAdministrators(Integer adminId) {
        return administratorsMapper.queryAdministrators(adminId);
    }

    @Override
    public int addAdministrators(Administrators administrators) {
        String s = new SimpleHash("md5", administrators.getAdminPassword(), "jiami", 2).toString();
        administrators.setAdminPassword(s);
        return administratorsMapper.addAdministrators(administrators);
    }

    @Override
    public List<Administrators> queryPremiereMenu() {
        return premiereMeunMapper.queryPremiereMenu();
    }

    @Override
    public int addAdministratorsPremiereMenu(Administrators administrators) {
        List<PremiereMeun> premiereMeuns = administrators.getPremiereMeuns();
        if (premiereMeuns!=null){
            for (PremiereMeun premiereMeun : premiereMeuns) {
                return administratorsMapper.addAdministratorsPremiereMenu(administrators.getAdminId(),premiereMeun.getPremiereMeunid());
            }
        }
        return 0;
    }

    @Override
    public int updateAdministrators(Administrators administrators) {
        String s = new SimpleHash("md5", administrators.getAdminPassword(), "jiami", 2).toString();
        administrators.setAdminPassword(s);
        return administratorsMapper.updateAdministrators(administrators);
    }

}